<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <th:block th:include="include :: header('工作模板列表')" />
</head>

<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>模板名称：</label>
                                <input type="text" name="templateName" />
                            </li>
                            <li>
                                <label>汇总类型：</label>
                                <select name="gatherFlag" th:with="type=${@dict.getType('gather_flag')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>模板状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="work:template:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
                    shiro:hasPermission="work:template:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                    shiro:hasPermission="work:template:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('work:template:edit')}]];
        var defineFlag = [[${@permission.hasPermi('work:template:define')}]];
        var removeFlag = [[${@permission.hasPermi('work:template:remove')}]];
        var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
        var gatherFlagDatas = [[${@dict.getType('gather_flag')}]];
        var prefix = ctx + "work/template";

        $(function () {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工作模板",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'templateId',
                    title: '模板ID',
                    visible: false
                },
                {
                    field: 'templateName',
                    title: '模板名称'
                },
                {
                    field: 'gatherFlag',
                    title: '汇总类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(gatherFlagDatas, value);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '模板状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + defineFlag + '" href="javascript:void(0)" onclick="page_define(\'' + row.templateId + '\')"><i class="fa fa-edit"></i>定义模板</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function page_define(templateId) {
            var url = prefix + "/define/" + templateId;
            $.modal.openTab('定义模板', url);
        }

        /* 模板状态显示 */
        function statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.templateId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.templateId + '\')"></i> ';
            }
        }

        /* 工作模板-启用 */
        function enable(templateId) {
            $.modal.confirm("确认要启用模板吗？", function () {
                $.operate.post(prefix + "/changeStatus", { "templateId": templateId, "status": 0 });
            })
        }

        /* 工作模板-停用 */
        function disable(templateId) {
            $.modal.confirm("确认要停用模板吗？", function () {
                $.operate.post(prefix + "/changeStatus", { "templateId": templateId, "status": 1 });
            })
        }
    </script>
</body>

</html>